package ch15;

import java.util.Scanner;

/**
 * Created by zhangyunqi on 2017/10/21.
 */
public class PascalTrangle {
    public static void main(String args[]) {
        System.out.println ("请输入杨辉三角打印行数：");
        Scanner scanner = new Scanner ( System.in );
        int line =scanner.nextInt ();
        System.out.println(" ");
        System.out.println ("杨辉三角：");
        int e[][];
        e = new int[line][];
        for (int q = 1; q <= line; q++) {
            e[q - 1] = new int[q];
        }
        for (int w = 0; w < line; w++) {
            for (int k = 0; k <= w; k++) {
                if (w == 0 || k == 0 || k == w)// 分支
                {
                    e[w][k] = 1;// 等于1的
                    continue;
                } else {
                    e[w][k] = e[w - 1][k - 1] + e[w - 1][k];// 计算值
                }
            }
        }
        for (int m = 0; m < line; m++) {
            for (int n = 0; n <= m; n++) {
                System.out.print(""+e[m][n] +" ");// 循环输出
            }
            System.out.println(" ");
        }
    }
}
